<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : productmessage.php   FILE_PATH : D:\webroot\mulitishop\home\productmessage.php
 * ....商品留言页面
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Fri Oct 12 18:40:01 CST 2007
 */

require ("../global.inc.php");

class ShowProductMessage extends CommonFrameWork{
	/**
	 * 留言对象
	 *
	 * @var obj
	 */
	var $obj_message;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 网站提醒对象
	 *
	 * @var obj
	 */
	var $obj_remind;
	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_product;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;

	function main(){
		/**
		 * 创建留言对象
		 */
		if (!is_object($this->obj_message)){
			require_once("productmessage.class.php");
			$this->obj_message = new ProductMessageClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("home");

		/**
		 * 语言包
		 */
		$this->getlang("product");

		switch($this->_input['action']){
			case "save":
				$this->_saveMessage();
				break;
			case "re":
				$this->_reMessage();
				break;
			case "resave":
				$this->_saveReMessage();
				break;
			case "del":
				$this->_delMessage();
				break;
		}
	}

	/**
	 * 保存留言
	 *
	 */
	function _saveMessage(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>strtoupper($this->_input['code']),"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>strtoupper($_SESSION['seccode']),"message"=>$this->_lang['errProductMCode']),
		array("input"=>$this->_input["txtMessage"],"require"=>"true","message"=>"请填写留言内容")
		);
//		$this->objvalidate->setValidate(array("input"=>strtoupper($this->_input['code']),"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>strtoupper($_SESSION['seccode']),"message"=>$this->_lang['errProductMCode']));  //您输入的验证码不对!
//		$this->objvalidate->setValidate(array("input"=>$this->_input["txtMessage"],"require"=>"true","message"=>"请填写留言内容"));
		/**
		 * 检验的错误信息
		 */

		$error = $this->objvalidate->validate();
		if ($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			/**
			 * 网站提醒操作
			 */
			if (!is_object($this->obj_remind)){
				require_once('remind.class.php');
				$this->obj_remind = new RemindClass();
			}
			/**
			 * 创建商品对象
			 */
			if (!is_object($this->obj_product)){
				require_once("product.class.php");
				$this->obj_product = new ProductClass();
			}
			/**
			 * 创建会员对象
			 */
			if (!is_object($this->obj_member)){
				require_once("member.class.php");
				$this->obj_member = new MemberClass();
			}

			/**
			 * 取商品信息
			 */
			$condition['p_id'] = $this->_input['hideproductID'];
			$condition['state'] = "none";
			$product_array = $this->obj_product->getProductList($condition, &$obj_page);
			
			$condition['id'] = $product_array[0]['member_id'];
			$member_array = $this->obj_member->getMemberInfo($condition);
	
			$value_array = array();
			$value_array['username'] = $member_array['login_name'];
			$value_array['product_name'] = $product_array[0]['p_name'];
			$this->obj_remind->setMessageOrMail('sale_message_product','message_product',$value_array,$member_array['login_name'],$this->_configinfo);
			
			
			
			$this->_input['MemberName'] = $_SESSION['s_login']['name'];
			$this->obj_message->addMessage($this->_input);   //将留言内容存放到数据库中
			$this->redirectPath("succ","","您发表留言成功！");
		}
	}

	/**
	 * 回复留言
	 *
	 */
	function _reMessage(){
		$message_array = $this->obj_message->getOneMessage($this->_input['messageid'],$_SESSION['s_login']['id']);    //得到某条留言内容
		$this->output('message_array',$message_array);   //输出留言内容
		$this->showpage('productmessage.re');
	}

	/**
	 * 回复留言存放到数据库中
	 *
	 */
	function _saveReMessage(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtReMessage"],"require"=>"true","message"=>"请填写回复内容")
		);
		/**
		 * 检验的错误信息
		 */
		$error = $this->objvalidate->validate();
		if ($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			$exist_array = array('messageid'=>$this->_input['hideMessageID'],'productid'=>$this->_input['hideproductID'],'memberid'=>$_SESSION['s_login']['id']);
			if ($this->obj_message->isExistMessage($exist_array)){
				$this->obj_message->reMessage($this->_input);   //将留言内容存放到数据库中

				/**
		     * 创建网站邮件发送内容信息对象
		     */
				if (!is_object($this->objcontent)){
					require_once("mailcontent.class.php");
					$this->objcontent = new MailContentClass();
				}
				$content = $this->objcontent->getMailContent("productreplay");   //获得发信内容
				if ($content['ifopen']){
					require_once("product.class.php");
					$obj_product = new ProductClass();
					$product_array = $obj_product->getProductRow($this->_input['hideproductID']);  //得到产品信息
					
					$message_array = $this->obj_message->getOneMessage($this->_input['hideMessageID'],$_SESSION['s_login']['id']);   //得到留言内容
					/**
		             * 创建发信对象
		             */
					if (!is_object($this->objmail)){
						require_once("sendmail.class.php");
						//$this->objmail = new SendMail($this->_configinfo['websit']['smtpserver'],$this->_configinfo['websit']['smtpprot'],true,$this->_configinfo['websit']['smtpuser'],$this->_configinfo['websit']['smtppass']);
					}
					$param = array(
					'productname'=>$product_array['p_name'],
					'producturl'=>$this->_configinfo['websit']['site_url'] . "/home/product.php?action=view&pid=" . $product_array['p_code'],
					'website'=>$this->_configinfo['websit']['site_title'],
					'site_url'=>$this->_configinfo['websit']['site_url'],
					'question'=>$message_array['message_content'],
					'messagetime'=>date("Y-m-d h:s",$message_array['message_time']),
					'reply'=>$message_array['message_recontent'],
					'username'=>$message_array['member_name'],
					'mastername'=>$_SESSION['s_login']['name']
					);
					$content['content'] = Common::replaceMailContent($param,$content['content']);   //将发信内容的变量换为值
					$content['title'] = Common::replaceMailContent($param,$content['title']);       //将发信标题的变量换为值
					echo $content['title'] . $content['content'];
					//$this->objmail->send($this->_input['txtemail'],$this->_configinfo['websit']['smtpemail'],$this->_configinfo['websit']['site_name'],$content['title'],$content['content']);   //发信
				}

				/**
				 * 网站提醒操作
				 */
				if (!is_object($this->obj_remind)){
					require_once('remind.class.php');
					$this->obj_remind = new RemindClass();
				}
				/**
				 * 创建商品对象
				 */
				if (!is_object($this->obj_product)){
					require_once("product.class.php");
					$this->obj_product = new ProductClass();
				}
				/**
				 * 创建会员对象
				 */
				if (!is_object($this->obj_member)){
					require_once("member.class.php");
					$this->obj_member = new MemberClass();
				}
	
				/**
				 * 取商品信息
				 */
				$condition['p_id'] = $this->_input['hideproductID'];
				$condition['state'] = "none";
				$product_array = $this->obj_product->getProductList($condition, &$obj_page);
				
				$condition['id'] = $product_array[0]['member_id'];
				$member_array = $this->obj_member->getMemberInfo($condition);
		
				$value_array = array();
				$value_array['username'] = $member_array['login_name'];
				$value_array['product_name'] = $product_array[0]['p_name'];
				$this->obj_remind->setMessageOrMail('buyer_message_seller_product_answer','message_seller_product_answer',$value_array,$member_array['login_name'],$this->_configinfo);
				
				
				$this->redirectPath("succ","home/product.php?action=view&pid=" . $this->_input['pid'],"您回复留言成功！");
			}else{
				$this->redirectPath("error","","留言不存在！");
			}
		}
	}

	/**
	 * 删除留言
	 *
	 */
	function _delMessage(){
		$this->obj_message->deleteOperateMessage($this->_input['messageid'],$_SESSION['s_login']['id']);
		$this->redirectPath("succ","home/product.php?action=view&pid=" . $this->_input['pid'],"您删除留言成功！");
	}
}

$productmessage = new ShowProductMessage();
$productmessage->main();
unset($productmessage);
?>